<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src=item.imgUrl>
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    'list': Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
      // list: [{
      //   id: '0001',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
      //   iconDesc: '景点门票'
      // }, {
      //   id: '0002',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/fc/b10a6b2e4f0fe102.png',
      //   iconDesc: '督公山滑雪'
      // }, {
      //   id: '0003',
      //   imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/a40ee278d67000f2a29d2e20f6a029b3.png',
      //   iconDesc: '自然风光'
      // }, {
      //   id: '0004',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/8246f27355943202.png',
      //   iconDesc: '游乐场'
      // }, {
      //   id: '0005',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/20/831d62d2e1c7be02.png',
      //   iconDesc: '窑湾古镇'
      // }, {
      //   id: '0006',
      //   imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20194/bf479a6bf700650fbc25837fea1c38e8.png',
      //   iconDesc: '徐州海底世界'
      // }, {
      //   id: '0007',
      //   imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20197/db518e3e320a84f206e6862c0baeeb32.png',
      //   iconDesc: '糖果世界'
      // }, {
      //   id: '0008',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/20/831d62d2e1c7be02.png',
      //   iconDesc: '潘安水镇'
      // }, {
      //   id: '0009',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png',
      //   iconDesc: '龟山汉墓'
      // }, {
      //   id: '0010',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
      //   iconDesc: '一日游'
      // }
      // ]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  @import "~styles/mixins"
  *{
    margin 0
    padding 0
    box-sizing border-box
  }
  .icons
    margin-top .1rem
    overflow hidden
    width 100%
    height 0
    padding-bottom 50%
    .icon
      position relative
      float left
      width 25%
      height 0
      // 注意这里的高度是父元素高度的一半
      // 这里的25%是宽度的百分之25
      // 有点难懂啊
      padding-bottom 25%
      .icon-img
        position absolute
        top 0
        right 0
        left 0
        bottom .44rem
        padding .1rem
        .icon-img-content
          height 100%
          margin 0 auto
          display block
      .icon-desc
        position absolute
        bottom 0
        left 0
        right 0
        line-height .44rem
        height .44rem
        color $darkTextColor
        text-align center
        ellipsis()
</style>
